import {AsyncStorage} from 'react-native'

const STORAGE_KEY = "STORAGE_KEY_notice";
export default {
    namespace: 'notice',
    state: {},
    reducers: {
        save(state, {payload}) {
            return {...state, ...payload}
        }
    },
    effects: {


        // 保存到本地
        * saveToStorage({payload}, {call}) {
            yield call(AsyncStorage.setItem, STORAGE_KEY, JSON.stringify(payload))
        },

        // 本地恢复
        * restoreFromStorage({payload}, {call, put, select}) {
            const data = yield call(AsyncStorage.getItem, STORAGE_KEY);
            yield put({
                type: 'save',
                payload: {...JSON.parse(data)}
            });
        },
        //清除数据
        * clear({payload}, {put}) {
        },
    },
    subscriptions: {
        setup({dispatch}) {

        }
    },
};
